package com.nervenets.web.hibernate.dao;

import com.nervenets.aspect.RedisAsyncLocker;
import com.nervenets.web.hibernate.domain.statistics.StatisticsOfOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface StatisticsOfOrderDao extends JpaRepository<StatisticsOfOrder, Long>, JpaSpecificationExecutor<StatisticsOfOrder> {
    StatisticsOfOrder findByCreateTime(int createTime);

    @Modifying
    @Transactional
    @Query(value = "update `statistics_of_order` set v = v + 1, total = total + ?1, money = money + ?2, first_time = first_time + ?3, finished = finished + ?4, cancel = cancel + ?5 where ct in (0,?6)", nativeQuery = true)
    void updateCount(int total, long money, int firstTime, int finished, int cancel, int time);
}
